package com.dq.controller.api.merchant.in.template;

import com.dq.domain.sys.user.Hobby;
import com.dq.domain.sys.user.UserHobby;
import com.dq.domain.sys.user.user.WxUser;
import com.dq.service.AllService;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/23 0023 17:26:53
 */
@Component
public class UtilsTemplate extends AllService {

    public List<Long> castArrays(String ids){
        String[] strings = ids.split("\\|");
        List<Long> longList = new ArrayList<>();
        for (String s:strings) {
            longList.add(Long.parseLong(s));
        }
        return longList;
    }

    public List<UserHobby> getUserHobby(String ids, WxUser wxUser){
        List<Long> longList = castArrays(ids);
        List<Hobby> hobbyList = hobbyRepositoty.findByIdIn(longList);
        List<UserHobby> userHobbyList = new ArrayList<>();
        hobbyList.forEach(hobby -> {
            UserHobby userHobby = new UserHobby();
            userHobby.setHobby(hobby);
            userHobby.setSysUser(wxUser);
            userHobbyList.add(userHobby);
        });
        return userHobbyList;
    }
}
